<div class="nav-sub w1180">
	<ul class="zoom">
		<li><a href="/crm/material/catelog-list">溯源类型列表</a></li>
		<li><a class="on" href="/crm/material/cate-list">溯源类目列表</a></li>
		<li><a href="/crm/material/list">溯源列表</a></li>
		<li><a href="/crm/material/report-list">溯源报告列表</a></li>
	</ul>
</div>
<div class="main-ct w1180">
	<div class="top-bar">
		<div class="custom-search">
			<label>类目名称<input type="text" class="tp-txt" id="material_category_name"></label> 
			<a href="javascript:search();" class="btn-cs btn-search ml5">查 询</a>
			<!-- 			<a href="javascript:;" class="btn-cs btn-green ml5">输出报表</a> -->
		</div>
		<a class="btn-cs btn-fillet btn-green" href="/crm/material/add-cate">新增类目</a>
	</div>
	<div id="list-table"></div>
</div>

<script type="text/javascript">
    var material_category_name = $("#material_category_name").val();
    var page = 1;
    
    $(document).ready(function(){
    	ajaxListTable();
    });
    
    function search(){

    	material_category_name = $("#material_category_name").val();
    
    	ajaxListTable();
    }
    
    function paginator(page_no) {
    	page = page_no;
    	ajaxListTable();
    }
    
    function ajaxListTable(){
    	$.ajax({
            type: "post",
            url: "<?php echo $this->url('crm/material', array( 'action' => 'ajax-material-cate-list'));?>",
            dataType:'html',
            data: { "material_category_name": material_category_name,
    				"page":page
    		},
            cache: false,
            timeout:10000, 
            error: function(){
              	 alert('请求超时，请重新操作');
               	 isPost = false;
                 return false; 
             }, 
            success: function(html){
            	$("#list-table").html(html);
            }
        });
    }

	function showpop(){
		$('.bgMask,.popup-form').show();
	}
	
	function hidepop(){

		$('.bgMask,.popup-form').hide();
		$(".bgMask,.popup-form").remove();
	}

	$('.btn-add-catalog').click(function(){
    	var html='';
    	html += '<div class="bgMask"></div>'
    		 + '<div class="popup popup-form">'
    		 + '<h4 class="txt-center">新增类型</h4>'
    		 + '<p><input type="text" id="catalog-name"></p>'
    		 + '<p class="txt-center"><a href="javascript:addCatalog();" class="btn-cs btn-fillet btn-green mt20 btn-sub">确定</a></p>'
    		 + '<a href="javascript:hidepop();" class="btn-close"></a>'
    		 + '</div>';
    		$('body').append(html);
    		$('.bgMask,.popup-form').show();
	})
	
	function addCatalog(){
		var CatalogName = $("#catalog-name").val();
		var data = {'catalog_name':CatalogName};
		$.post("/crm/material/insertCatelog", data, response, 'json');
	}

    function response(res){
    	hidepop();
        alert(res.reason);
    }

</script>